package com.example.a02back.common;

import java.io.Serializable;

/**
 * @ClassName APIResponse
 * @Description
 * @Author SimpChaos
 * @Date 2022/6/18 9:27
 * @Version 1.0
 **/
public class APIResponse<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private int code;
    private String message;
    private T data;

    private APIResponse(int code,String message,T data){
        this.code=code;
        this.message=message;
        this.data=data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> APIResponse<T> success(String message,T data) {
        APIResponse<T> response = new APIResponse<T>(0,message,data);
        return response;
    }

    public static <T> APIResponse<T> success() {
        return success("",null);
    }

    public static <T> APIResponse<T> fail(String message) {
        APIResponse<T> response = new APIResponse<T>(-1,message,null);
        return response;
    }

    public static <T> APIResponse<T> fail() {
        return fail("failure");
    }
}

